/**
 * 
 */
package design_pattern.interpreter;

/**
 * @author linzq
 * 
 */
public class Constant implements Expression {

  private boolean value;

  public Constant(boolean value) {
    this.value = value;
  }

  /**
   * 解释操作
   */
  @Override
  public boolean interpret(Context ctx) {
    return value;
  }

  @Override
  public int hashCode() {
    return this.toString().hashCode();
  }

  @Override
  public boolean equals(Object obj) {
    if (obj != null && obj instanceof Constant) {
      return this.value == ((Constant) obj).value;
    }
    return false;
  }

  @Override
  public String toString() {
    return new Boolean(this.value).toString();
  }

}
